import { defHttp } from "/@/utils/http/axios";
import { Modal } from "ant-design-vue";

export enum Api {
  list      = "/manager/order/order/dataGrid",
  detail    = "/manager/order/order/",
  queryById = "/buyer/order/order/queryById",

  visitorLoad   = "/buyer/visitor/visitor/load",
  visitorById   = "/buyer/visitor/visitor/get",
  visitorSave   = "/buyer/visitor/visitor/save",
  visitorDelete = "/buyer/visitor/visitor/delete"
}

/**
 * 预订审核 - 列表
 * @param params
 */
export const list = async (params) => await defHttp.get({url: Api.list, params});

/**
 * 预订审核 - 详情
 * @param params
 */
export const detail = (params) => defHttp.get({url: Api.detail + params.orderSn}, {isTransformResponse:false});

/**
 * 预订审核 - 预订
 * @param params
 */
export const queryById = (params) => defHttp.get({url: Api.queryById, params}, {isTransformResponse:false});

//----------------------后台-------------------------------------------

/**
 * 预订审核 - 修改
 * @param params
 */
export const modify = (sn, params) => defHttp.put({url: `/manager/order/order/update/${sn}/tourPrice`, params}, {joinParamsToUrl:false, isTransformResponse:false});

/**
 * 预订审核 - 审核
 * @param params
 */
export const audit = (params, handleSuccess) => {
  var url = `/manager/order/order/${params.orderSn}/audit`;
  defHttp.post({ url: url, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
}

/**
 * 预订审核 - 撤销
 * @param params
 */
export const revise = (params, handleSuccess) => {
  var url = `/manager/order/order/${params}/revise`;
  defHttp.post({ url: url }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
}

/**
 * 预订审核 - 撤销
 * @param params
 */
export const repeal = (params) => {
  var url = `/manager/order/order/repeal`;
  defHttp.get({ url: url, params }, { joinParamsToUrl: true });
}


/**
 * 游客 - 列表
 * @param params
 */
export const visitorLoad = (params) => defHttp.get({url: Api.visitorLoad, params}, {joinParamsToUrl: true, isTransformResponse:false});


/**
 * 游客 - 信息
 * @param params
 */
export const visitorById = (params) => defHttp.get({url: Api.visitorById, params}, {joinParamsToUrl: true});

/**
 * 游客 - 保存
 * @param params
 */
export const visitorSave = (params) => defHttp.post({url: Api.visitorSave, params}, {joinParamsToUrl: true, isTransformResponse:false});

/**
 * 删除单个
 * @param params
 * @param handleSuccess
 */
export const visitorDelete = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.visitorDelete, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
}
